﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Globalization;
using HA.MT3DMS.DomainLayer;

namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winMTOutputControl.xaml 的交互逻辑
    /// </summary>
    public partial class winMT3DOutputControl : Window
    {
        public winMT3DOutputControl(MTOutputControl outputControl)
        {
            InitializeComponent();

            this._pcOutputControl =(MTOutputControl)outputControl.Clone();

            this.DataContext = this._pcOutputControl;
        }

        MTOutputControl _pcOutputControl;

        public MTOutputControl PcOutputControl
        {
            get { return _pcOutputControl; }
            set { _pcOutputControl = value; }
        }

        private void btnTimes_Click(object sender, RoutedEventArgs e)
        {
            winMTOutputControlTimes winTimes = new winMTOutputControlTimes(this._pcOutputControl.Timesteps);
            winTimes.Owner = this;
            winTimes.ShowDialog();
            if (winTimes.DialogResult == true)
            {
                this.PcOutputControl.Timesteps = winTimes.Times;
               
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (this._pcOutputControl.StepsType == TimeStepType.SpecifiedTimes)
            {
                this.rbtnTimes.IsChecked = true;
            }
            else if (this._pcOutputControl.StepsType == TimeStepType.SpecifiedInterval)
            {
                this.rbtnInterval.IsChecked = true;
            }
            else
            {
                this.rbtnSimulation.IsChecked = true;
            }
        }

        private void rbtnTimes_Checked(object sender, RoutedEventArgs e)
        {
            if (this.rbtnTimes.IsChecked.Value)
            {
                this._pcOutputControl.StepsType = TimeStepType.SpecifiedTimes;
            }
        }

        private void rbtnSimulation_Checked(object sender, RoutedEventArgs e)
        {
            if (this.rbtnSimulation.IsChecked.Value)
            {
                this._pcOutputControl.StepsType = TimeStepType.EndSimulation;
            }
        }

        private void rbtnInterval_Checked(object sender, RoutedEventArgs e)
        {
            if (this.rbtnInterval.IsChecked.Value)
            {
                this._pcOutputControl.StepsType = TimeStepType.SpecifiedInterval;
            }
        }

    }

    public class PrintTypeToEnumConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int index=0;
            switch((PrintType)value)
            {
                case PrintType.NotPrint: index = 2; break;
                case PrintType.StripForm: index = 1; break;
                case PrintType.WrapForm: index = 0; break;
            }
            return index;

        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            PrintType newValue = PrintType.NotPrint;
            switch ((int)value)
            {
            case 0: newValue = PrintType.WrapForm;break;
            case 1: newValue = PrintType.StripForm; break;
            case 2: newValue = PrintType.NotPrint; break;
            }
            return newValue;

        }
    }

    public class TimeStepTypeToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool newValue;
            switch ((TimeStepType)value)
            {
                case TimeStepType.SpecifiedTimes: newValue = true; break;
                default: newValue = false; break;
            }
            return newValue;

        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TimeStepType newValue;
            switch ((bool)value)
            {
                case true: newValue = TimeStepType.SpecifiedTimes; break;
                default: newValue = TimeStepType.EndSimulation; break;
            }
            return newValue;

        }

    }
}
